﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using JESAI.Authorize.Abstractions;
using JESAI.Authorize.Implementation;
using System.Linq;
using System.Text;
using System;

namespace JESAI.Authorization.SQLite
{
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// mysql user scope authorize
        /// </summary>
        /// <param name="authoriserBuilder"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public static IAuthoriserBuilder UseSQLiteAuthorize(this IAuthoriserBuilder authoriserBuilder, string section = "JwtAuthorize")
        {
            var config = authoriserBuilder.Configuration.GetSection(section);
            authoriserBuilder.Services.AddSingleton<IPermissionRepository>(sp => new SQLitelPermissionRepository(config["SQLiteConnectionString"], config["ProjectName"]));
            authoriserBuilder.Services.AddSingleton<IPermissionAuthoriser, ScopesAuthoriser>();
            return authoriserBuilder;
        }
    }
}
